package com.service.impl;

import com.domain.entity.Bill;
import com.domain.entity.User;
import com.domain.req.PageReq;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.BillMapper;
import com.service.BillService;
import com.utils.JWTUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author caishenao
 * @description 针对表【bill(账单表)】的数据库操作Service实现
 * @createDate 2023-10-29 13:53:53
 */
@Service
public class BillServiceImpl implements BillService {

    @Resource
    private BillMapper billMapper;

    /**
     * 分页查询个人的账单数据
     *
     * @param pageReq 分页请求
     * @return 分页的账单数据
     */
    @Override
    public PageInfo<Bill> pageList(PageReq pageReq) {
        // 1. 获取当前用户
        User currentUser = JWTUtils.getCurrentUser();
        PageHelper.startPage(pageReq.getPageNum(), pageReq.getPageSize());
        List<Bill> list = billMapper.list(currentUser.getId());
        PageInfo<Bill> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}




